# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.

defmodule GoogleApi.Firestore.V1beta1.Model.BloomFilter do
  @moduledoc """
  A bloom filter (https://en.wikipedia.org/wiki/Bloom_filter). The bloom filter hashes the entries with MD5 and treats the resulting 128-bit hash as 2 distinct 64-bit hash values, interpreted as unsigned integers using 2's complement encoding. These two hash values, named `h1` and `h2`, are then used to compute the `hash_count` hash values using the formula, starting at `i=0`: h(i) = h1 + (i * h2) These resulting values are then taken modulo the number of bits in the bloom filter to get the bits of the bloom filter to test for the given entry.

  ## Attributes

  *   `bits` (*type:* `GoogleApi.Firestore.V1beta1.Model.BitSequence.t`, *default:* `nil`) - The bloom filter data.
  *   `hashCount` (*type:* `integer()`, *default:* `nil`) - The number of hashes used by the algorithm.
  """

  use GoogleApi.Gax.ModelBase

  @type t :: %__MODULE__{
          :bits => GoogleApi.Firestore.V1beta1.Model.BitSequence.t() | nil,
          :hashCount => integer() | nil
        }

  field(:bits, as: GoogleApi.Firestore.V1beta1.Model.BitSequence)
  field(:hashCount)
end

defimpl Poison.Decoder, for: GoogleApi.Firestore.V1beta1.Model.BloomFilter do
  def decode(value, options) do
    GoogleApi.Firestore.V1beta1.Model.BloomFilter.decode(value, options)
  end
end

defimpl Poison.Encoder, for: GoogleApi.Firestore.V1beta1.Model.BloomFilter do
  def encode(value, options) do
    GoogleApi.Gax.ModelBase.encode(value, options)
  end
end
